GBML manual / Drawing

draw_sprite

Draws a sprite at (x, y) with a specific frame - world space (the shared camera is attached, same as default drawing). Inside a Draw GUI event it is fixed to the screen instead, and (x, y) counts from the screen’s top-left pixel.

Works differently on Game Boy - A sprite drawn with draw_sprite takes places among the 40 sprites the Game Boy shows at once (10 on one line): a big picture takes several, and one that does not fit is not drawn.

Works differently on Game Boy Color - A sprite drawn with draw_sprite takes places among the 40 sprites the Game Boy Color shows at once (10 on one line): a big picture takes several, and one that does not fit is not drawn.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_sprite(spr, x, y, frame = 0)

Arguments

NameType
sprsprite
xreal
yreal
frameint (can be left out; then it is 0)

Returns

Nothing.

Description

Draws one extra sprite in world space (it scrolls with the room, the same shared camera default drawing uses), at a position and frame you choose (leave frame out for the first picture, frame 0) independently of this instance's own x/y/frame - a status icon floating above a character, a muzzle flash offset from the gun, a shadow pinned a few pixels below the feet. Called every frame it should stay visible; stop calling it and the sprite is released on its own, nothing to clean up by hand.

x and y are a place in the room, counted from the room's top-left corner. The sprite is drawn with its origin (the middle of the picture, unless you set another) on that spot.

In a Draw GUI event the same call is fixed to the screen instead: x and y count from the top-left pixel of the screen, the sprite never scrolls with the camera, and it is in front of the whole world - a heart for each life, an ammo icon, a cursor. There is no other call for this: a sprite on the screen is a draw_sprite in a Draw GUI event.

Example

draw_sprite(spr_doc_glow, x, y - 12, 0);

Draws a small glow icon a fixed 12 pixels above this instance's own position, every frame - a simple "this one is special" marker that moves with the instance without being part of its own sprite.

A real capture - the amber glow icon drawn 12 pixels above the arrow, as its own separate spriteA real capture - the amber glow icon drawn 12 pixels above the arrow, as its own separate sprite
A real capture - the amber glow icon drawn 12 pixels above the arrow, as its own separate sprite

On the GBA

Cached per call site: calling this with the same arguments every frame reuses last frame’s sprite rather than rebuilding it - stop calling it and the sprite is released on its own at the end of that frame, no cleanup needed. frame can be left out: draw_sprite(spr_icon, x, y) is draw_sprite(spr_icon, x, y, 0), the first picture.

See also: draw_sprite_scaleddraw_self